//
//  String+Extention.swift
//  微博来源
//
//  Created by macs on 15/11/22.
//  Copyright © 2015年 BlackTail. All rights reserved.
//

import Foundation

extension String {
    
    
    func getSourceString () -> (linkString : String?, souceString : String?){
        
        //创建匹配方案
        let  paraten = "<a href=\"(.*?)\" rel=\".*?\">(.*?)</a>"
        //正则取值
        let regular = try! NSRegularExpression(pattern: paraten, options: [])
        //返回值
        let result = regular.firstMatchInString(self, options: [], range: NSRange(location: 0,length: characters.count))
        
        let  range1 = result?.rangeAtIndex(1)
        let range2 = result?.rangeAtIndex(2)
        var str1 : String?
        var str2 : String?
        if let r1 = range1 , r2 = range2 {
             str1 = (self as NSString).substringWithRange(r1)
             str2 = (self as NSString).substringWithRange(r2)
        }
        
        return (str1,str2)
    }
    
}